/*
 * @Author: mikey.zhaopeng 
 * @Date: 2018-12-16 09:20:03 
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2018-12-16 10:20:36
 */
import 'package:flutter/material.dart';
//导入四个自页面
import './dynamic_page.dart';
import './home_page.dart';
import './lib_page.dart';
import './rank_page.dart';

class TabPage extends StatefulWidget {
  @override
  _TabPageState createState() => new _TabPageState();
}

class _TabPageState extends State<TabPage> with SingleTickerProviderStateMixin {
  int _tabIndex = 0;
  PageController pageController;
  List<Widget> _bodys;

  @override
  void initState() {
    super.initState();
    _bodys = [
      HomePage(),
      RankPage(),
      LibPage(),
      DynamicPage(),
    ];
    pageController = new PageController(initialPage: _tabIndex);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView.builder(
        itemBuilder: (BuildContext context, int index) {
          return _bodys[_tabIndex];
        },
        controller: pageController,
        itemCount: _bodys.length,
        onPageChanged: (int index) {
          setState(() {
            _tabIndex = index;
          });
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: <BottomNavigationBarItem>[
          new BottomNavigationBarItem(
            title: Text("首页"),
            icon: Icon(Icons.home),
          ),
          new BottomNavigationBarItem(
            title: Text("排行"),
            icon: Icon(Icons.local_play),
          ),
          new BottomNavigationBarItem(
            title: Text("片库"),
            icon: Icon(Icons.ondemand_video),
          ),
          new BottomNavigationBarItem(
            title: Text("动态"),
            icon: Icon(Icons.camera),
          ),
        ],
        currentIndex: _tabIndex,
        onTap: (int index) {
          setState(() {
            _tabIndex = index;
            // pageController.animateToPage(_tabIndex,
            //     duration: Duration(milliseconds: 10), curve: Curves.easeInOut);
          });
        },
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}
